﻿@*@model IEnumerable<DOTNET_ASSIGNMENT.Models.File>*@

@model PagedList.IPagedList<DOTNET_ASSIGNMENT.Models.File>
@using PagedList.Mvc;

<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
<link href="~/Content/ProgressBar.css" rel="stylesheet" />

@{
    ViewBag.Title = "Manage";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm("Manage", "Account", FormMethod.Get))
{
    <p>
        @Html.TextBox("SearchString", ViewBag.CurrentFilter as string, new { @placeholder = "Search..." })
        <input type="submit" value="Search" />
    </p>
}

@{
    var message = TempData["AlertMessage"] ?? string.Empty;
}

<table class="file_content">
    <thead>
        <tr>
            <th>
                @Html.ActionLink("Name", "Manage", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })
            </th>
            <th>
                @Html.ActionLink("Size", "Manage", new { sortOrder = ViewBag.SizeSortParm, currentFilter = ViewBag.CurrentFilter })
            </th>
            <th>
                <a href="#" name="Extension">Extension</a>
            </th>
            <th>
                @Html.ActionLink("Date", "Manage", new { sortOrder = ViewBag.DateSortParm, currentFilter = ViewBag.CurrentFilter })
            </th>
            <th>
                Action
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.DisplayName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Size)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Extension)
                </td>
               
                <td>
                    @Html.DisplayFor(modelItem => item.Date)
                </td>
                <td>
                    @using (Html.BeginForm("DeleteFile", "Account", new { name = item.DisplayName }))
                    {
                        @*@Html.ActionLink("Download", "Download", new { ImageName = item.DisplayName }, new { target = "_blank" })*@
                        <a href="@Url.Action("Download", "Account", new { imageName = item.DisplayName })" target="_blank">
                            <input type="button" value="Download" />
                        </a>
                        <a href="@Url.Action("Share", "Account", new { imageName = item.DisplayName })">
                            <input type="button" value="Share"/>
                        </a>
                        <input type="submit" value="Delete" onclick="return confirm('Are you sure want to delete @item.DisplayName')" />
                    }
                </td>
            </tr>
        }
    </tbody>
</table>
<br />
<span>Page</span> @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount

@Html.PagedListPager(Model, page => Url.Action("Manage",
    new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))


<br />
@using (Ajax.BeginForm("Manage", "Account", new AjaxOptions { HttpMethod = "POST" }, new { id = "ajaxform", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    <input type="file" name="files" id="ful" value="Choose File" />
    <input type="submit" value="Upload File" />    <br />

    //<div id="status"></div>
}


@section scripts {
    <script src="~/Scripts/jQuery_malsup.js"></script>

    <script type="text/javascript">
        var message = '@message';
        if (message)
            alert(message);
    </script>

    <script>
        (function () {
            var bar = $('.progressbar');
            var percent = $('.progressbar');
            var status = $('#status');

            $('form#ajaxform').ajaxForm({
                beforeSend: function () {
                    status.empty();
                    var percenValue = '0%';
                    bar.width(percenValue);
                    percent.html('Uploading...');
                },
                uploadProgess: function (event, position, total, percentComplete) {
                    var percentValue = percentComplete + '%';
                    bar.width(percentValue);
                    percent.html('Uploading...');
                },
                success: function (d) {
                    var percentValue = '100%';
                    bar.width(percentValue);
                    percent.html('Done');
                    $('#ful').val('');
                    alert(d);
                    window.location.href = '/Account/Manage';
                },
                //complete: function (xhr) {
                //    status.html(xhr.responseText);
                //}
            });
        })();
    </script>
}
